﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace idataplatform
{
    public partial class fglcounting : Form
    {
        public fglcounting()
        {
            InitializeComponent();
        }

        private void fglcounting_Load(object sender, EventArgs e)
        {
            conncls conns = new conncls();
            string fgledateSQL = "SELECT DATE_FORMAT(MAX(xftime),'%Y年%c月%d日') FROM xfjd_ipark;";
            string fglsdateSQL = "SELECT DATE_FORMAT(DATE_ADD(MAX(xftime),interval -365 day),'%Y年%c月%d日') FROM xfjd_ipark;";
            dateTimePicker1.Text = conns.varStr(fglsdateSQL);
            dateTimePicker2.Text = conns.varStr(fgledateSQL);

            label4.Text = "会员复购率=一年内有过2次及以上消费的会员人数/一年内有过消费的会员总人数";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            conncls conns = new conncls();
            string fgnoSQL = "SELECT COUNT(CISHU) FROM (SELECT COUNT(HYNO) AS CISHU FROM xfjd_ipark WHERE xftime>= '"+dateTimePicker1.Value.ToShortDateString()+ "' AND xftime<= '" + dateTimePicker2.Value.AddDays(1).ToShortDateString() + "' GROUP BY HYNO,phoneno HAVING CISHU > 1) A;";
            string xfnoSQL = "SELECT COUNT(DISTINCT HYNO) FROM xfjd_ipark WHERE xftime>= '" + dateTimePicker1.Value.ToShortDateString() + "' AND xftime<= '" + dateTimePicker2.Value.AddDays(1).ToShortDateString() + "';";
            int fgno = conns.varInt(fgnoSQL);
            int xfno = conns.varInt(xfnoSQL);
            textBox1.Text = Math.Round((Convert.ToDouble(fgno) / Convert.ToDouble(xfno)), 4).ToString("0.00%");
            textBox2.Text = fgno.ToString();
            textBox3.Text = xfno.ToString();
        }
    }
}
